# -*- coding: utf-8 -*-
"""
Created on Sun May 22 14:47:15 2022

@author: 77998
"""

# -*- coding: utf-8 -*-
"""
Created on Mon Apr 18 16:08:23 2022

@author: 77998
"""

import matplotlib.pyplot as plt
import os
from sklearn import metrics
from scipy.io import savemat
import matplotlib.pyplot as plt
from sklearn.metrics import plot_roc_curve, precision_recall_curve
from sklearn.metrics import auc
from matplotlib.patches import  ConnectionPatch

from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes
from mpl_toolkits.axes_grid1.inset_locator import mark_inset

import numpy as np
plt.rcParams.update({'font.size': 12})
plt.rc('font',family='Times New Roman')

fig, ax = plt.subplots()

fpr1 = np.loadtxt("D:/罗的论文/评价指标/fpr1.csv")
tpr1 = np.loadtxt("D:/罗的论文/评价指标/tpr1.csv")
# recall1 = np.loadtxt("recall1.txt")
# pre1 = np.loadtxt("precision1.txt")
auroc1 = auc(fpr1, tpr1)
# aupr1 = auc(recall1, pre1)
ax.plot(fpr1, tpr1, label=u'dataset1(AUROC = %0.3f)'% auroc1)
fpr2 = np.loadtxt("D:/罗的论文/评价指标/fpr2.csv")
tpr2 = np.loadtxt("D:/罗的论文/评价指标/tpr2.csv")
auroc2 = auc(fpr2, tpr2)
ax.plot(fpr2, tpr2, label=u'dataset2(AUROC = %0.3f)'% auroc2)
fpr3 = np.loadtxt("D:/罗的论文/评价指标/fpr3.csv")
tpr3 = np.loadtxt("D:/罗的论文/评价指标/tpr3.csv")
auroc3 = auc(fpr3, tpr3)
ax.plot(fpr3, tpr3, label=u'dataset3(AUROC = %0.3f)'% auroc3)
ax.set_xlabel('False Positive Rate')
ax.set_ylabel('True Positive Rate')
ax.set_title('Receiver Operating Characteristic on Three Datasets')
ax.legend(loc='lower right')

# extent = [-3, 4, -4, 3]

axins = zoomed_inset_axes(ax, 2,loc='center')  # zoom = 6
axins.plot(fpr1,tpr1)
axins.plot(fpr2,tpr2)
axins.plot(fpr3,tpr3)


# sub region of the original image
x1, x2, y1, y2 = 0.0, 0.2, 0.85, 0.99
axins.set_xlim(x1, x2)
axins.set_ylim(y1, y2)
# fix the number of ticks on the inset axes
axins.yaxis.get_major_locator().set_params(nbins=5)
axins.xaxis.get_major_locator().set_params(nbins=5)


#plt.xticks(visible=True,fontsize=18)
#plt.yticks(visible=True,fontsize=18)

mark_inset(ax, axins, loc1=1, loc2=2, fc="none", ec="0.5")
plt.savefig("revise-auc-dpi-3.jpg",dpi=300, bbox_inches='tight')
plt.show()

# def read_score_label_auc(file_dir):
#     fpr = np.loadtxt(open(os.path.join(file_dir,"label.csv"),"rb"),delimiter=",")
#     tpr = np.loadtxt(open(os.path.join(file_dir,"score.csv"),"rb"),delimiter=",")
#     auroc = auc(fpr, tpr)
#     print(auroc)
#     return auroc, fpr,tpr

# def read_score_label_aupr(file_dir):
#     real_score = np.loadtxt(open(os.path.join(file_dir,"label.csv"),"rb"),delimiter=",")
#     predict_score = np.loadtxt(open(os.path.join(file_dir,"score.csv"),"rb"),delimiter=",")
#     aupr = metrics.average_precision_score(real_score, predict_score)
#     print(aupr)
#     precision, recall, thresholds = precision_recall_curve(real_score, predict_score)
#     return aupr, precision, recall



# fig, ax=plt.subplots(1, 2, dpi=300)
#
#
# ax[0].set_title("(a)",y=-0.15)
# ax[0].set_ylabel('True Positive Rate')
# ax[0].set_xlabel('False Positive Rate')
# ax[0].set_xlim([-0.1,1.1])
# ax[0].set_ylim([-0.1,1.1])


#-----------DRRS
# filenames1 = './DRRS/F' # refer root dir
# auc1,fpr1,tpr1 = read_score_label_auc(filenames1)
# fpr1 = np.loadtxt("fpr1.csv")
# tpr1 = np.loadtxt("tpr1.csv")
# auroc1 = auc(fpr1, tpr1)
# ax[0].plot(fpr1,tpr1,label=u'dataset1(AUROC = %0.3f)'% auroc1)
# plt.plot([0,1],[0,1],'r--')

#----------layer2
# filenames2 = './BNNR/F' # refer root dir
# auc2,fpr2,tpr2 = read_score_label_auc(filenames2)
# fpr2 = np.loadtxt("fpr2.csv")
# tpr2 = np.loadtxt("tpr2.csv")
# auroc2 = auc(fpr2, tpr2)
# ax[0].plot(fpr2,tpr2,label=u'dataset2(AUROC = %0.3f)'% auroc2)


#-----------att3
# filenames3 = './SCMPF/F' # refer root dir
# auc3,fpr3,tpr3 = read_score_label_auc(filenames3)
# fpr3 = np.loadtxt("fpr2.csv")
# tpr3 = np.loadtxt("tpr2.csv")
# auroc3 = auc(fpr3, tpr3)
# ax[0].plot(fpr3,tpr3,label=u'dataset3(AUROC = %0.3f)'% auroc3)


#-----------no att
# filenames4 = './LAGCN/F' # refer root dir
# auc4,fpr4,tpr4 = read_score_label_auc(filenames4)
# ax[0].plot(fpr4,tpr4,label=u'LAGCN(AUROC = %0.3f)'% auc4)
#
#
# filenames5 = './DRWBNCF/F' # refer root dir
# auc5,fpr5,tpr5 = read_score_label_auc(filenames5)
# ax[0].plot(fpr5,tpr5,color='yellowgreen',label=u'DRWBNCF(AUROC = %0.3f)'% auc5)
#
#
# #---opt
# filenames_opt = './my/F' # refer root dir
# auc6,fpr6,tpr6 = read_score_label_auc(filenames_opt)
# ax[0].plot(fpr6,tpr6,color='m',label=u'GLGMPNN(AUROC = %0.3f)'% auc6)
#plt.plot([0,1],[0,1],'r--')
#ax[0].legend(bbox_to_anchor=(1.05, 0), loc=3, borderaxespad=0,fontsize=16)
#ax[0].legend(loc='best',fontsize=16)

# extent = [-3, 4, -4, 3]

# axins = zoomed_inset_axes(ax[0], 3,loc='center right')  # zoom = 6
# axins.plot(fpr1,tpr1)
# axins.plot(fpr2,tpr2)
# axins.plot(fpr3,tpr3)
# axins.plot(fpr4,tpr4)
# axins.plot(fpr5,tpr5,color='yellowgreen')
# axins.plot(fpr6,tpr6,color='m')

# sub region of the original image
# x1, x2, y1, y2 = 0.05, 0.25, 0.8, 0.93
# axins.set_xlim(x1, x2)
# axins.set_ylim(y1, y2)
# # fix the number of ticks on the inset axes
# axins.yaxis.get_major_locator().set_params(nbins=5)
# axins.xaxis.get_major_locator().set_params(nbins=5)


#plt.xticks(visible=True,fontsize=18)
#plt.yticks(visible=True,fontsize=18)
#
# ax[0].legend(loc='best',fontsize=18)
#
# # draw a bbox of the region of the inset axes in the parent axes and
# # connecting lines between the bbox and the inset axes area
# # mark_inset(ax[0], axins, loc1=1, loc2=2, fc="none", ec="0.5")
#
# plt.draw()
# plt.show()
# # plt.tight_layout()
# plt.tight_layout(pad=0.4, w_pad=0.5, h_pad=5.0)
# plt.savefig("revise-auc-dpi-3.jpg",dpi=300)


#------------------aupr

# extent = [-3, 4, -4, 3]
#
# axins = zoomed_inset_axes(ax[1], 3,loc='center right')  # zoom = 6
# axins.plot(fpr1,tpr1)
# axins.plot(fpr2,tpr2)
# axins.plot(fpr3,tpr3)
#
#
# # # sub region of the original image
# # x1, x2, y1, y2 = 0.05, 0.25, 0.8, 0.93
# # axins.set_xlim(x1, x2)
# # axins.set_ylim(y1, y2)
# # fix the number of ticks on the inset axes
# axins.yaxis.get_major_locator().set_params(nbins=5)
# axins.xaxis.get_major_locator().set_params(nbins=5)
#
# plt.xticks(visible=True,fontsize=18)
# plt.yticks(visible=True,fontsize=18)
#
# mark_inset(ax[1], axins, loc1=1, loc2=2, fc="none", ec="0.5")
# ax[1].legend(loc='best',fontsize=18)
#
#
# plt.draw()
# plt.show()
# plt.tight_layout()
# plt.tight_layout(pad=0.4, w_pad=0.5, h_pad=5.0)
# plt.savefig("revise-auc-dpi-3.jpg",dpi=300)